<template>
  <view
    v-if="openModal"
    class="wx-modal"
  >
    <view
      class="wam__mask"
      @touchmove.prevent=""
      @tap.stop="closeModal"
    ></view>
    
    <!-- 内容区域 -->
    <view class="wam__wrapper">
      <!-- 关闭按钮 -->
      <!-- <view class="wam__close-btn" @tap.stop="closeModal">
        <text class="tn-icon-close"></text>
      </view> -->
      <view class="tn-text-center tn-text-lg">
        相关推荐
      </view>
      
      <view class="tn-padding-top-sm">
        
        <scroll-view scroll-y="true" style="max-height: 60vh;">
        
          <!-- 商品 start-->
          <view class="tn-flex tn-flex-wrap" style="margin: 10rpx 19rpx;">
            <block v-for="(item, index) in content" :key="index">
              <view class="" style="width: 50%;" @click="tn('/productPages/details')">
                <view class="tn-product-content__wrap">
                  <view class="image-picproduct" :style="'background-image:url(' + item.mainImage + ')'">
                    <view class="image-product">
                      <view class="tn-flex tn-flex-row-right" style="width: 100%;position: absolute;bottom: 0;right: 0;">
                        <tn-button size="sm" shape="icon" backgroundColor="#FFFFFF80" fontColor="#DF3C39" margin="10rpx">
                          <text class="tn-icon-add tn-text-lg"></text>
                        </tn-button>
                      </view>
                    </view>
                  </view>
                  
                  <view class="tn-product-content__label tn-text-justify tn-padding-sm tn-padding-bottom-xs">
                    <text class="tn-product-content__label__desc clamp-text-1">{{ item.desc }}</text>  
                  </view>
                  
                  <view class="tn-flex tn-flex-row-between tn-flex-col-center tn-padding-sm tn-padding-top-xs">
                    <view class="justify-content-item tn-flex tn-flex-col-center" style="margin-left: -2rpx;color: #DF3C39;">
                      <text class="tn-text-sm" style="padding-right: 2rpx;">￥</text>
                      <text class="tn-padding-right-sm tn-text-xl ">{{ item.price }}</text>
                      <!-- <text class="tn-color-gray tn-text-sm"> 66 人购买</text> -->
                    </view>
                    <view class="justify-content-item tn-flex tn-flex-col-center">
                      <text class="tn-color-gray tn-text-sm"> {{ item.number }} 人购买</text>
                      <!-- <tn-button size="sm" shape="icon" backgroundColor="#3e486400" fontColor="#3e4864" padding="10rpx 0 0 0" shadow>
                        <text class="tn-icon-buy tn-text-lg"></text>
                      </tn-button> -->
                    </view>
                  </view>
                </view>
              </view>
            </block>
          </view>
          <!-- 商品 end-->
          
          <view class="tn-tabbar-height"></view>
        
        </scroll-view>
        
      </view>
      
    </view>
  </view>
</template>

<script>
  
  export default {
    options: {
      // 在微信小程序中将组件节点渲染为虚拟节点，更加接近Vue组件的表现(不会出现shadow节点下再去创建元素)
      virtualHost: true
    },
    props: {
      value: {
        type: Boolean,
        default: false
      }
    },
    data() {
      return {
        openModal: false,
        
        content: [{
            price: '59.00',
            number: '18',
            desc: '凶姐到此一游',
            mainImage: 'https://cdn.nlark.com/yuque/0/2024/jpeg/280373/1708654911753-assets/web-upload/54515f42-8f03-4f08-9760-c7ba02ef6aa9.jpeg',
          },
          {
            price: '38.00',
            number: '21',
            desc: '抓住那只猪',
            mainImage: 'https://cdn.nlark.com/yuque/0/2024/jpeg/280373/1708654911753-assets/web-upload/54515f42-8f03-4f08-9760-c7ba02ef6aa9.jpeg',
          },
          {
            price: '29.00',
            number: '19',
            desc: '猪猪不见了',
            mainImage: 'https://cdn.nlark.com/yuque/0/2024/jpeg/280373/1708654911753-assets/web-upload/54515f42-8f03-4f08-9760-c7ba02ef6aa9.jpeg',
          },
          {
            price: '59.00',
            number: '12',
            desc: '吖猪吖猪',
            mainImage: 'https://cdn.nlark.com/yuque/0/2024/jpeg/280373/1708654911753-assets/web-upload/54515f42-8f03-4f08-9760-c7ba02ef6aa9.jpeg',
          },
          {
            price: '79.00',
            number: '6',
            desc: '一棵葡萄树',
            mainImage: 'https://cdn.nlark.com/yuque/0/2024/jpeg/280373/1708654911753-assets/web-upload/54515f42-8f03-4f08-9760-c7ba02ef6aa9.jpeg',
          },
          {
            price: '88.00',
            number: '16',
            desc: '迷路的猪',
            mainImage: 'https://cdn.nlark.com/yuque/0/2024/jpeg/280373/1708654911753-assets/web-upload/54515f42-8f03-4f08-9760-c7ba02ef6aa9.jpeg',
          },
          {
            price: '59.00',
            number: '2',
            desc: '图鸟那只猪',
            mainImage: 'https://cdn.nlark.com/yuque/0/2024/jpeg/280373/1708654911753-assets/web-upload/54515f42-8f03-4f08-9760-c7ba02ef6aa9.jpeg',
          },
          {
            price: '69.00',
            number: '22',
            desc: '凶姐到此一游然后迷路了真可怜',
            mainImage: 'https://cdn.nlark.com/yuque/0/2024/jpeg/280373/1708654911753-assets/web-upload/54515f42-8f03-4f08-9760-c7ba02ef6aa9.jpeg',
          }
        ],
      }
    },
    watch: {
      value: {
        handler(val) {
          this.openModal = val
        },
        immediate: true
      }
    },
    methods: {
      
      // 关闭弹框
      closeModal() {
        this.$emit('input', false)
      },
      
    }
  }
</script>

<style lang="scss" scoped>
  
  /* 文字截取*/
  .clamp-text-1 {
    -webkit-line-clamp: 1;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    text-overflow: ellipsis;
    overflow: hidden;
  }
  
  .clamp-text-2 {
    -webkit-line-clamp: 2;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    text-overflow: ellipsis;
    overflow: hidden;
  }
  
  
  .wx-modal {
    position: fixed;
    left: 0;
    top: 0;
    width: 100vw;
    height: 100vh;
    z-index: 99998 !important;
    
    view {
      box-sizing: border-box;
    }
    
    .image {
      width: 100%;
      height: 100%;
      border-radius: inherit;
    }
    
    .wam {
      z-index: 9999 !important;
      /* mask */
      &__mask {
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        height: 100%;
        background-color: rgba(0, 0, 0, 0.5);
        opacity: 0;
        animation: showMask 0.25s linear 0s forwards;
      }
      
      /* close-btn */
      &__close-btn {
        position: absolute;
        top: 30rpx;
        right: 30rpx;
        z-index: 99999;
        font-size: 40rpx;
      }
      
      /* wrapper */
      &__wrapper {
        position: absolute;
        left: 0;
        bottom: 0;
        width: 100%;
        background-color: #FFFFFF;
        border-radius: 40rpx 40rpx 0rpx 0rpx;
        padding-top: 40rpx;
        // padding-bottom: 40rpx;
        // padding-bottom: calc(constant(safe-area-inset-bottom) + 40rpx);
        // padding-bottom: calc(env(safe-area-inset-bottom) + 40rpx);
        transform-origin: center bottom;
        transform: scaleY(0);
        animation: showWrapper 0.25s linear 0s forwards;
        z-index: 99999;
      }
      
    }
  }
  
  @keyframes showMask {
    0% {
      opacity: 0;
    }
    100% {
      opacity: 1;
    }
  }
  @keyframes showWrapper {
    0% {
      transform: scaleY(0);
      opacity: 0;
    }
    100% {
      transform: scaleY(1);
      opacity: 1;
    }
  }
  
  /* 底部悬浮按钮 start*/
  .tn-tabbar-height {
  	min-height: 20rpx;
  	height: calc(40rpx + env(safe-area-inset-bottom) / 2);
    height: calc(40rpx + constant(safe-area-inset-bottom));
  }
  .tn-footerfixed {
    width: 100%;
    margin-top: 60rpx;
    margin-bottom: calc(env(safe-area-inset-bottom)- 20rpx );
    z-index: 1024;
    box-shadow: 0 1rpx 6rpx rgba(0, 0, 0, 0);
  
  }
  /* 底部悬浮按钮 end*/
  
  /* 商家商品 start*/
  .tn-product-content {
    &__wrap {
      // box-shadow: 0rpx 0rpx 50rpx 0rpx rgba(0, 0, 0, 0.07);
      border-radius: 15rpx;
      background-color: #F6F6F6;
      margin: 11rpx;
    }
    
    &__info {
      &__btn {
        margin-right: -12rpx;
        opacity: 0.5;
      }
    }
    
    &__label {
      
      &__desc {
        line-height: 35rpx;
      }
    }
  }
  
  .image-product{
    padding: 185rpx 0rpx;
    font-size: 16rpx;
    position: relative;
  }
  .image-picproduct{
    background-size: cover;
    background-repeat:no-repeat;
    // background-attachment:fixed;
    background-position:center;
    border-radius: 15rpx 15rpx 0 0;
  }
  
  /* 商家商品 end*/
  
</style>